package lol.niconico.libtest.ui.other

import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
import android.widget.Toast
import androidx.activity.viewModels
import androidx.lifecycle.observe
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.android.synthetic.main.activity_main.*
import lol.niconico.libtest.R
import lol.niconico.libtest.TestData
import lol.niconico.libtest.di.AnalyticsAdapter
import lol.niconico.libtest.di.AnalyticsService
import lol.niconico.libtest.di.L
import lol.niconico.libtest.http.Client
import lol.niconico.libtest.http.Server
import lol.niconico.libtest.task.ExamViewModel
import lol.niconico.libtest.ui.camera.CameraActivity
import lol.niconico.libtest.ui.paging.PagingActivity
import javax.inject.Inject

@AndroidEntryPoint
class MainActivity : AppCompatActivity() {

    @Inject
    lateinit var analytics: L

    @Inject
    lateinit var service: AnalyticsService

    @Inject
    lateinit var analyticsAdapter: AnalyticsAdapter

    @Inject
    lateinit var testData: TestData

    private val viewModel by viewModels<ExamViewModel>()

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        button.setOnClickListener {
            Toast.makeText(this, testData.toString(), Toast.LENGTH_SHORT).show()
        }

        button2.setOnClickListener {
            Toast.makeText(this, viewModel.getValue(), Toast.LENGTH_SHORT).show()
        }

        button3.setOnClickListener {
            Toast.makeText(this, service.toString(), Toast.LENGTH_SHORT).show()
            Server.webSocket.send("Server:" + System.currentTimeMillis().toString())
        }

        button4.setOnClickListener {
            Client.webSocket.send("Client" + System.currentTimeMillis().toString())
            Toast.makeText(this, analyticsAdapter.service.toString(), Toast.LENGTH_SHORT)
                .show()
        }

        button5.setOnClickListener {
            startActivity(Intent(this, CameraActivity::class.java))
        }

        button6.setOnClickListener {
            startActivity(Intent(this, PagingActivity::class.java))
        }

        viewModel.testLiveData.observe(this) {
            Log.e("testLiveData", it)
        }
        Server.startServer()
    }
}
